
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;
import java.sql.*;

final class NewSolidLoanOrder extends javax.swing.JInternalFrame {

    Systems systems=new Systems();
    Object[][] tableObject=new Object[][]{{null,null,null,null,null,null}};
    PreparedStatement statement;
    PreparedStatement statement2;
    String addInUse="N", delInUse="N";
    String solidReceivablesOrderCode,solidPayablesOrderCode;
    Thread processThread=new Thread();
    Thread titleThread=new Thread();

    /** Creates new form NewCreditOrder */
    public NewSolidLoanOrder() {
        initComponents();
        setTitle("::. New Inventory Payable Credit Order By User ("+OpenMSApp.EmployeeName+")");
        reset();
        JPopupMenu popup=new JPopupMenu();
        JMenuItem menuPopup=new JMenuItem("Select Item");
        popup.add(menuPopup);
        jTable1.setComponentPopupMenu(popup);
        menuPopup.addActionListener(new java.awt.event.ActionListener(){
        public void actionPerformed(java.awt.event.ActionEvent e){
        
        String v=new ItemList(OpenMS_FinanceAdmin_Desktop.appFrame,true).getSelectedItem();
        if(v==null||v.equalsIgnoreCase("null"))return;
        
        jTable1.setValueAt(v, jTable1.getRowCount()-1, 1);
        }});
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jNameTextField = new javax.swing.JTextField();
        merchantIDComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jDateTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTotAmountTextField = new javax.swing.JTextField();
        makeOrderButton = new javax.swing.JButton();
        addRowButton = new javax.swing.JButton();
        deleteRowButton = new javax.swing.JButton();
        jRefDepartmentComboBox = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jSolidReceivablesAccountNameComboBox = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jTransactionNoTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTransactionTypeComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jCostOrderCodeComboBox = new javax.swing.JComboBox();
        transMonthComboBox = new javax.swing.JComboBox();
        transDayComboBox = new javax.swing.JComboBox();
        transYearComboBox = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel12 = new javax.swing.JLabel();
        jSolidPayablesAccountNameComboBox = new javax.swing.JComboBox();
        jSRActUnitTextField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jSPActUnitTextField = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jAmtDueTextField = new javax.swing.JTextField();
        jToBalanceTextField = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(NewSolidLoanOrder.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jNameTextField.setEditable(false);
        jNameTextField.setText(resourceMap.getString("jNameTextField.text")); // NOI18N
        jNameTextField.setName("jNameTextField"); // NOI18N
        jNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jNameTextFieldActionPerformed(evt);
            }
        });

        merchantIDComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        merchantIDComboBox.setName("merchantIDComboBox"); // NOI18N
        merchantIDComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                merchantIDComboBoxActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jDateTextField.setEditable(false);
        jDateTextField.setText(resourceMap.getString("jDateTextField.text")); // NOI18N
        jDateTextField.setName("jDateTextField"); // NOI18N
        jDateTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDateTextFieldActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTotAmountTextField.setEditable(false);
        jTotAmountTextField.setName("jTotAmountTextField"); // NOI18N
        jTotAmountTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTotAmountTextFieldActionPerformed(evt);
            }
        });

        makeOrderButton.setIcon(resourceMap.getIcon("makeOrderButton.icon")); // NOI18N
        makeOrderButton.setText(resourceMap.getString("makeOrderButton.text")); // NOI18N
        makeOrderButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        makeOrderButton.setName("makeOrderButton"); // NOI18N
        makeOrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                makeOrderButtonActionPerformed(evt);
            }
        });

        addRowButton.setIcon(resourceMap.getIcon("addRowButton.icon")); // NOI18N
        addRowButton.setText(resourceMap.getString("addRowButton.text")); // NOI18N
        addRowButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        addRowButton.setName("addRowButton"); // NOI18N
        addRowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addRowButtonActionPerformed(evt);
            }
        });

        deleteRowButton.setIcon(resourceMap.getIcon("deleteRowButton.icon")); // NOI18N
        deleteRowButton.setText(resourceMap.getString("deleteRowButton.text")); // NOI18N
        deleteRowButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        deleteRowButton.setName("deleteRowButton"); // NOI18N
        deleteRowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteRowButtonActionPerformed(evt);
            }
        });

        jRefDepartmentComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jRefDepartmentComboBox.setName("jRefDepartmentComboBox"); // NOI18N
        jRefDepartmentComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefDepartmentComboBoxActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jSolidReceivablesAccountNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jSolidReceivablesAccountNameComboBox.setName("jSolidReceivablesAccountNameComboBox"); // NOI18N
        jSolidReceivablesAccountNameComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSolidReceivablesAccountNameComboBoxActionPerformed(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jTransactionNoTextField.setName("jTransactionNoTextField"); // NOI18N
        jTransactionNoTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTransactionNoTextFieldActionPerformed(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTransactionTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jTransactionTypeComboBox.setName("jTransactionTypeComboBox"); // NOI18N
        jTransactionTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTransactionTypeComboBoxActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jCostOrderCodeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jCostOrderCodeComboBox.setEnabled(false);
        jCostOrderCodeComboBox.setName("jCostOrderCodeComboBox"); // NOI18N
        jCostOrderCodeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCostOrderCodeComboBoxActionPerformed(evt);
            }
        });

        transMonthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Month --" }));
        transMonthComboBox.setName("transMonthComboBox"); // NOI18N
        transMonthComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transMonthComboBoxActionPerformed(evt);
            }
        });

        transDayComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Day --" }));
        transDayComboBox.setName("transDayComboBox"); // NOI18N

        transYearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Year --" }));
        transYearComboBox.setName("transYearComboBox"); // NOI18N

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setEnabled(false);
        jCheckBox1.setName("jCheckBox1"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jSolidPayablesAccountNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jSolidPayablesAccountNameComboBox.setName("jSolidPayablesAccountNameComboBox"); // NOI18N
        jSolidPayablesAccountNameComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSolidPayablesAccountNameComboBoxActionPerformed(evt);
            }
        });

        jSRActUnitTextField.setEditable(false);
        jSRActUnitTextField.setName("jSRActUnitTextField"); // NOI18N
        jSRActUnitTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSRActUnitTextFieldActionPerformed(evt);
            }
        });

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jSPActUnitTextField.setEditable(false);
        jSPActUnitTextField.setName("jSPActUnitTextField"); // NOI18N
        jSPActUnitTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSPActUnitTextFieldActionPerformed(evt);
            }
        });

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jAmtDueTextField.setText(resourceMap.getString("jAmtDueTextField.text")); // NOI18N
        jAmtDueTextField.setName("jAmtDueTextField"); // NOI18N
        jAmtDueTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jAmtDueTextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jAmtDueTextFieldKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jAmtDueTextFieldKeyTyped(evt);
            }
        });

        jToBalanceTextField.setEditable(false);
        jToBalanceTextField.setName("jToBalanceTextField"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jCheckBox3.setText(resourceMap.getString("jCheckBox3.text")); // NOI18N
        jCheckBox3.setName("jCheckBox3"); // NOI18N
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jCheckBox4.setText(resourceMap.getString("jCheckBox4.text")); // NOI18N
        jCheckBox4.setName("jCheckBox4"); // NOI18N
        jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4ActionPerformed(evt);
            }
        });

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jCheckBox3))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(95, 95, 95)
                        .addComponent(jDateTextField))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel9)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(merchantIDComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(transMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(transDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(transYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTransactionTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jNameTextField)
                            .addComponent(jTransactionNoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(jTotAmountTextField)
                            .addComponent(jAmtDueTextField)
                            .addComponent(jToBalanceTextField))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel5)
                                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel6))
                                    .addComponent(jLabel10))
                                .addGap(1, 1, 1))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jSPActUnitTextField)
                            .addComponent(jSRActUnitTextField)
                            .addComponent(jRefDepartmentComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jSolidReceivablesAccountNameComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jCostOrderCodeComboBox, 0, 234, Short.MAX_VALUE)
                            .addComponent(jSolidPayablesAccountNameComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(42, 42, 42)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(makeOrderButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(deleteRowButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addRowButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jCheckBox4)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(merchantIDComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTransactionTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTransactionNoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(transDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(transYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTotAmountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jAmtDueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jToBalanceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jDateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox4))
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jCostOrderCodeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSolidReceivablesAccountNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSolidPayablesAccountNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRefDepartmentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSRActUnitTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSPActUnitTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(addRowButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deleteRowButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(makeOrderButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(99, Short.MAX_VALUE))
        );

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "S/N", "Item", "Description", "Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTable1PropertyChange(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTable1KeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 980, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jDateTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDateTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jDateTextFieldActionPerformed

    private void jNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jNameTextFieldActionPerformed

    private void jTotAmountTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTotAmountTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTotAmountTextFieldActionPerformed

    private void makeOrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_makeOrderButtonActionPerformed
       
            /* Execute thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                performMakeOrder();
                
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("viewIPDebitThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
    }//GEN-LAST:event_makeOrderButtonActionPerformed
    public void performMakeOrder(){
    
        if(merchantIDComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT TRANSACTION BY (ID) ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        int x=tableObject.length;
        int y=x+1;
        for(int z=0;z<x;z++)
        {
            if(jTable1.getValueAt(z,1)==null||jTable1.getValueAt(z,2)==null||jTable1.getValueAt(z,3)==null||jTable1.getValueAt(z,4)==null||jTable1.getValueAt(z,5)==null)
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"NULL VALUE FOUND IN TABLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
            String dActName=jSolidPayablesAccountNameComboBox.getSelectedItem().toString().trim();
            String cActName=jSolidReceivablesAccountNameComboBox.getSelectedItem().toString().trim();

       int a=tableObject.length;
       int b=0;


        while(b<a)
        {
            String value=jTable1.getValueAt(b,3).toString().trim();

            String value2=jTable1.getValueAt(b,4).toString().trim();
            String value3=jTable1.getValueAt(b,5).toString().trim();

        if(!systems.isStringDecimal(value))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"QUANTITY MUST BE IN DIGIT","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!systems.isStringDecimal(value2))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"RATE MUST BE IN MONEY FORMAT","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!systems.isStringDecimal(value3))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"AMOUNT MUST BE IN MONEY FORMAT","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        /**
            String selectedAccountCode=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+cActName+"'","cAccountCode" );
            String accountCategory=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+cActName+"'","cCategory" );
            String value4=jTable1.getValueAt(b,1).toString().trim();
            String itemCode=systems.getValue(OpenMSApp.Database_A, "Select * from item where vName='"+value4+"'", 1);
            String orderCode[]=systems.getOrderCode(itemCode);
            if(orderCode.length>0)
            {
                String accountCode=systems.getValue(OpenMSApp.Database_A, "Select * from creditOrder where cCreditOrderCode='"+orderCode[0]+"'", "cAccountCode");
                String actualAccountName=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where cAccountCode='"+accountCode+"'","vAccountName" );
                if(accountCode.equalsIgnoreCase(selectedAccountCode)==false&& accountCategory.equalsIgnoreCase("INVENTORY"))
                {
                    JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Item '"+value4+"' must be credited into account '"+actualAccountName+"' only.","ERROR !",JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            **/
        b+=1;
        if(b==a){break;}
        }
        if(!systems.isStringDecimal(jTotAmountTextField.getText().trim()))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"TOTAL AMOUNT RESULT IN AN ERROR !","ERROR !",JOptionPane.ERROR_MESSAGE);
            //reset();
            return;
        }
        if(!systems.isStringDecimal(jToBalanceTextField.getText().trim()))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"TO BALANCE RESULTS IN AN ERROR !","ERROR !",JOptionPane.ERROR_MESSAGE);
            //reset();
            return;
        }
        if(jAmtDueTextField.getText().trim().equalsIgnoreCase("."))
        {           
        
            int i=JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), " ARE YOU SURE 'AMOUNT DUE = TOTAL AMOUNT' ?", "WARNING !",JOptionPane.YES_NO_OPTION);
            if(i==JOptionPane.NO_OPTION)
            {
                return;
            }
       }
        if(jSolidReceivablesAccountNameComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT AN ACCOUNT ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jRefDepartmentComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT A REFERAL DEPARTMENT ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(transMonthComboBox.getSelectedItem().equals("-- Month --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT TRANSACTION'S DATE MONTH ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(transDayComboBox.getSelectedItem().equals("-- Day --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT TRANSACTION'S DATE DAY ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(transYearComboBox.getSelectedItem().equals("-- Year --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT TRANSACTION'S DATE YEAR ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jSolidPayablesAccountNameComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT INVENTORY PAYABLE ACCOUNT ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jSolidReceivablesAccountNameComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT INVENTORY ACCOUNT ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        String accountName=String.valueOf(jSolidReceivablesAccountNameComboBox.getSelectedItem());
        String accountStatus=systems.getValue(OpenMSApp.Database_A, "Select * from Account where vAccountName='"+accountName+"'", "cStatus");
        if(accountStatus.equalsIgnoreCase("Frozen"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED INVENTORY ACCOUNT IS FROZEN ! \n SEE YOUR ACCOUNT ADMINISTRATOR FOR DETAILS.","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        String spAccountName=String.valueOf(jSolidPayablesAccountNameComboBox.getSelectedItem());
        String spAccountStatus=systems.getValue(OpenMSApp.Database_A, "Select * from Account where vAccountName='"+spAccountName+"'", "cStatus");
        if(spAccountStatus.equalsIgnoreCase("Frozen"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED INVENTORY ACCOUNT IS FROZEN ! \n SEE YOUR ACCOUNT ADMINISTRATOR FOR DETAILS.","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jSolidPayablesAccountNameComboBox.getSelectedItem().equals("-- Select --")==false||jSolidReceivablesAccountNameComboBox.getSelectedItem().equals("-- Select --")==false)
        {

            String creditAccountCur=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+cActName+"'","vAccountUnit" );
            String debitAccountCur=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+dActName+"'","vAccountUnit" );
            if(creditAccountCur.equalsIgnoreCase(debitAccountCur)==false)
            {
                int i=JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), " SELECTED ACCOUNTS CURRENCIES DID NOT MATCH !\n DO YOU WANT TO PROCEED TRANSACTION ?", "WARNING !",JOptionPane.YES_NO_OPTION);
                if(i==JOptionPane.NO_OPTION)
                {
                    return;
                }
            }
        }
        makeOrder();
        printReceipt();
        printReceipt2();
        //reset();
    }
    private void merchantIDComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_merchantIDComboBoxActionPerformed
        merchantIDSelected();
    }//GEN-LAST:event_merchantIDComboBoxActionPerformed
     private void merchantIDSelected()
    {
        String merchantID=merchantIDComboBox.getSelectedItem().toString();
        if(merchantID.equals("-- Select --"))
        {
            /* Execute thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetMerchantID();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
        else
        {
            jNameTextField.setText(systems.getValue(OpenMSApp.Database_A, "Select * from vwMerchant where cMerchantID = '"+merchantID+"'", "vName"));
        }
    }                                                            
    public void calculateToBalance()
    {
        String dueValue=jAmtDueTextField.getText();
        if(dueValue.equalsIgnoreCase(".")){dueValue=jTotAmountTextField.getText();}
        String totAmtValue=jTotAmountTextField.getText();
        String toBalance=systems.getValue(OpenMSApp.Database_A, Connect.procInit+"  prnSubtractMoney"+Connect.procInitStart+""+dueValue+" , "+totAmtValue+Connect.procInitEnd, "mSumValue");
       try{
            jToBalanceTextField.setText(systems.converToRealMoneyFormat(toBalance)); 
       }
       catch(Exception e){
            jToBalanceTextField.setText("Er!M1C01K0");
       }
    }
    public void addRow()
    {
        String v=new ItemList(OpenMS_FinanceAdmin_Desktop.appFrame,true).getSelectedItem();
        if(v==null||v.equalsIgnoreCase("null"))return;
        
        addInUse="Y";
        int x=tableObject.length;
        int y=x+1;
        Object[][] holdObject=new Object[y][6];

        for(int z=0;z<x;z++)
        {
            if(jTable1.getValueAt(z,1)==null||jTable1.getValueAt(z,2)==null||jTable1.getValueAt(z,3)==null||jTable1.getValueAt(z,4)==null||jTable1.getValueAt(z,5)==null)
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Null value found ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
        }

        for(int z=0;z<x;z++)
        {
            if(jTable1.getValueAt(z,1)!=null&&jTable1.getValueAt(z,2)!=null&&jTable1.getValueAt(z,3)!=null&&jTable1.getValueAt(z,4)!=null&&jTable1.getValueAt(z,5)!=null)
            {
                holdObject[z][0]=z+1;
                holdObject[z][1]=jTable1.getValueAt(z,1).toString();
                holdObject[z][2]=jTable1.getValueAt(z,2).toString();
                holdObject[z][3]=jTable1.getValueAt(z,3).toString();
                holdObject[z][4]=jTable1.getValueAt(z,4).toString();
                holdObject[z][5]=jTable1.getValueAt(z,5).toString();
                holdObject[y-1][0]=y;
            }
        }

        tableObject=holdObject;

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Item","Description", "Quantity", "Rate", "Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true, true, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
            resetItem();
            addInUse="N";
        jTable1.setValueAt(v, jTable1.getRowCount()-1, 1);
        
    }
    private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed
        // TODO add your handling code here:
        addRow();
    }//GEN-LAST:event_addRowButtonActionPerformed
    public void deleteRow()
    {
        delInUse="Y";
        int x=tableObject.length;
        int y=x-1;
        Object[][] holdObject=new Object[y][6];


            if(x==1)
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Can Not Delete Row \n   Invalid Operation ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }

        for(int z=0;z<x-1;z++)
        {
            if(jTable1.getValueAt(z,1)!=null&&jTable1.getValueAt(z,2)!=null&&jTable1.getValueAt(z,3)!=null&&jTable1.getValueAt(z,4)!=null&&jTable1.getValueAt(z,5)!=null)
            {
                holdObject[z][0]=z+1;
                holdObject[z][1]=jTable1.getValueAt(z,1).toString();
                holdObject[z][2]=jTable1.getValueAt(z,2).toString();
                holdObject[z][3]=jTable1.getValueAt(z,3).toString();
                holdObject[z][4]=jTable1.getValueAt(z,4).toString();
                holdObject[z][5]=jTable1.getValueAt(z,5).toString();
                holdObject[y-1][0]=y;
            }
        }
        tableObject=holdObject;

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Item","Description", "Quantity", "Rate", "Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true, true, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
        resetItem();
        delInUse="N";
    }
    private void deleteRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRowButtonActionPerformed
        // TODO add your handling code here:
        deleteRow();
    }//GEN-LAST:event_deleteRowButtonActionPerformed

    private void jTable1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable1KeyTyped

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
        // TODO add your handling code here:
        System.out.println("Key Pressed on JTable1");
    }//GEN-LAST:event_jTable1KeyPressed

    private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTable1PropertyChange
        /* Execute submit thread*/
        processThread=new Thread(new Runnable() {
            public void run() {
            //disableControls();
               freeHeap();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                //enableControls();
                //System.out.println("tablePropertyThread stopped runing.");

            }
        });
        processThread.start();
        titleThread.start(); 
    }//GEN-LAST:event_jTable1PropertyChange
    synchronized void freeHeap()
    {
        Systems.getInstance().freeHeap();         
        if(!systems.freeingHeap)
        tablePropertyChange();
    }
    synchronized void tablePropertyChange()
    {
        if(systems.freeingHeap)return;
        if(addInUse.equals("N")&&delInUse.equals("N")){
        int x=jTable1.getEditingRow();
        int y=jTable1.getEditingColumn();

        int value=0;
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";


            int a=tableObject.length;
            int b=0;
            while(b<a)
            {
                if(jTable1.getValueAt(b,1)!=null&&b==a-1&&jCheckBox3.isSelected()==false)
                {
                    String itemCost=systems.getValue(OpenMSApp.Database_A, "Select * from item where vName='"+jTable1.getValueAt(b,1)+"'", 7);
                    jTable1.setValueAt(itemCost,b,4);
                    String itemDescr=systems.getValue(OpenMSApp.Database_A, "Select * from item where vName='"+jTable1.getValueAt(b,1)+"'", 3);
                    jTable1.setValueAt(itemDescr,b,2);
                    
                }
                if(jTable1.getValueAt(b,3)!=null && jTable1.getValueAt(b,4)!=null)
                {
                        String value2=jTable1.getValueAt(b,3).toString().trim();

                        String value3=jTable1.getValueAt(b,4).toString().trim();

                        //String value4=jTable1.getValueAt(b,5).toString().trim();

                        if(!systems.isStringDecimal(value2))
                        {
                            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"QUANTITY MUST BE IN DIGIT/DECIMAL","ERROR !",JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                        if(!systems.isStringDecimal(value3))
                        {
                            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"RATE MUST BE IN MONEY FORMAT","ERROR !",JOptionPane.ERROR_MESSAGE);
                            return;
                        }
//                        if(!systems.isStringDecimal(value4))
//                        {
//                            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"AMOUNT MUST BE IN MONEY FORMAT","ERROR !",JOptionPane.ERROR_MESSAGE);
//                            return;
//                        }
                }
                if(jTable1.getValueAt(b,3)!=null&&jTable1.getValueAt(b, 4)!=null)
                {
                    String quantityValue="0";
                    String priceValue="0";
                    String multValue="0";

                    try
                    {
                        quantityValue=systems.converToRealMoneyFormat(jTable1.getValueAt(b, 3).toString());
                    }
                    catch(Exception e)
                    {
                        quantityValue="Er!M1C01K0";
                    }
                    try
                    {
                        priceValue=systems.converToRealMoneyFormat(jTable1.getValueAt(b, 4).toString());
                    }
                    catch(Exception e)
                    {
                        priceValue="Er!M1C01K0";
                    }
                    try
                    {
                        multValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnMultMoney"+Connect.procInitStart+""+quantityValue+" , "+priceValue+Connect.procInitEnd, "mMultValue");

                        jTable1.setValueAt(systems.converToRealMoneyFormat(multValue), b, 5);
                    }
                    catch(Exception e)
                    {
                        jTable1.setValueAt("Er!M1C01K0", b, 5);
                    }
                }
                if(jTable1.getValueAt(b,5)!=null)
                {
                    firstValue=sumValue;
                    try
                    {
                        secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(b,5).toString());
                    }
                    catch(Exception e)
                    {
                        secondValue="Er!M1C01K0";
                    }
                    sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+"  prnAddMoney"+Connect.procInitStart+""+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                    System.out.println(firstValue+" "+secondValue+" "+sumValue);
                }
                b+=1;
                if(b==a){break;}
            }
        try
        {
            jTotAmountTextField.setText(systems.converToRealMoneyFormat(sumValue));
        }
        catch(Exception e)
        {
            jTotAmountTextField.setText("Er!M1C01K0");
        }
        }
        calculateToBalance();
}
    private void jRefDepartmentComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefDepartmentComboBoxActionPerformed
        
        String refDepartment=jRefDepartmentComboBox.getSelectedItem().toString();
        if(refDepartment.equals("-- Select --"))
        { /* Execute submit thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetRefDepartment();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
    }//GEN-LAST:event_jRefDepartmentComboBoxActionPerformed

    private void jSolidReceivablesAccountNameComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSolidReceivablesAccountNameComboBoxActionPerformed
        
        String srActName=jSolidReceivablesAccountNameComboBox.getSelectedItem().toString().trim();
        if(srActName.equals("-- Select --"))
        {/* Execute submit thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetSolidReceivablesAccountName();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
        else
        {
            jSRActUnitTextField.setText(systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+srActName+"'","vAccountUnit" ));
        }
        
    }//GEN-LAST:event_jSolidReceivablesAccountNameComboBoxActionPerformed

    private void jTransactionNoTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTransactionNoTextFieldActionPerformed
        // TODO add your handling code here:
        String value=jTransactionNoTextField.getText();
        if(value.length()>49)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (50) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
            String newValue=String.copyValueOf(value.toCharArray(),0, 49);
            jTransactionNoTextField.setText(newValue);
        }
    }//GEN-LAST:event_jTransactionNoTextFieldActionPerformed

    private void jTransactionTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTransactionTypeComboBoxActionPerformed
        String transType=jTransactionTypeComboBox.getSelectedItem().toString();
        if(transType.equals("-- Select --"))
        {
            /* Execute thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetTransactionType();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
    }//GEN-LAST:event_jTransactionTypeComboBoxActionPerformed

    private void jCostOrderCodeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCostOrderCodeComboBoxActionPerformed
        
        String costOrderCode=jCostOrderCodeComboBox.getSelectedItem().toString();
        if(costOrderCode.equals("-- Select --"))
        { /* Execute submit thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetCostOrderCode();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
        else
        {
        }
    }//GEN-LAST:event_jCostOrderCodeComboBoxActionPerformed

    private void transMonthComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transMonthComboBoxActionPerformed
        // TODO add your handling code here:
        String transMonth=transMonthComboBox.getSelectedItem().toString();

        if(transMonth.equals("-- Month --")) {
        } else {
            resetTransDay(transMonth);
        }
    }//GEN-LAST:event_transMonthComboBoxActionPerformed

    private void jSolidPayablesAccountNameComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSolidPayablesAccountNameComboBoxActionPerformed
        
        String spActName=jSolidPayablesAccountNameComboBox.getSelectedItem().toString().trim();
        if(spActName.equals("-- Select --"))
        {
            /* Execute thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                resetSolidPayablesAccountName();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("newCreditOrderThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
        /*
        if(cActName.equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," PLEASE SELECT CREDITING ACCOUNT ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
         *
         */
        else
        {
            jSPActUnitTextField.setText(systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+spActName+"'","vAccountUnit" ));
        }

    }//GEN-LAST:event_jSolidPayablesAccountNameComboBoxActionPerformed

    private void jSRActUnitTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSRActUnitTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jSRActUnitTextFieldActionPerformed

    private void jSPActUnitTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSPActUnitTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jSPActUnitTextFieldActionPerformed

private void jAmtDueTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAmtDueTextFieldKeyPressed
// TODO add your handling code here:
        calculateToBalance();
}//GEN-LAST:event_jAmtDueTextFieldKeyPressed

private void jAmtDueTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAmtDueTextFieldKeyReleased
// TODO add your handling code here:
        calculateToBalance();
}//GEN-LAST:event_jAmtDueTextFieldKeyReleased

private void jAmtDueTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAmtDueTextFieldKeyTyped
// TODO add your handling code here:
        calculateToBalance();
}//GEN-LAST:event_jAmtDueTextFieldKeyTyped

private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCheckBox3ActionPerformed

private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCheckBox4ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    if(processThread.isAlive())
    {
        try{
            processThread.stop();
            titleThread.stop();
            System.out.println("Threads successfully stopped.");
        }catch(Exception e){System.out.println("Thread stopping error: "+e);}
        this.setTitle("::. New Inventory Payable Credit Order By User ("+OpenMSApp.EmployeeName+")");
        enableControls();
    }
    else
        dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    public void resetTransYear()
    {
        String[] year=systems.getYears(1920);
        year[0]="-- Year --";
        transYearComboBox.setModel(new DefaultComboBoxModel(year));
    }
    public void resetTransMonth()
    {
        String[] month=systems.getMonthArray();
        month[0]="-- Month --";

        transMonthComboBox.setModel(new DefaultComboBoxModel(month));

    }
    public void resetTransDay(String Month)
    {
        String[] day={"-- Day --"};
        if(Month.isEmpty())
        {
            transDayComboBox.setModel(new DefaultComboBoxModel(day));
        }
        else
        {
            day=systems.getDays(Month);
            day[0]="-- Day --";
            transDayComboBox.setModel(new DefaultComboBoxModel(day));
        }

    }
    public String getCostOrderCode()
    {
        String costOrderCode=String.valueOf(jCostOrderCodeComboBox.getSelectedItem()).trim();

        if(costOrderCode.equals("-- Select --"))
        {
            costOrderCode="";
        }
        return costOrderCode;

    }
    public void makeOrder()
    {
        String departmentName=String.valueOf(jRefDepartmentComboBox.getSelectedItem()).trim();
        String solidReceivablesAccountName=String.valueOf(jSolidReceivablesAccountNameComboBox.getSelectedItem()).trim();
        String transactionType=String.valueOf(jTransactionTypeComboBox.getSelectedItem()).trim();
        solidReceivablesOrderCode=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnPrintCreditOrderCode"+Connect.procInitStart+Connect.procInitEnd, "cCode");

        String refCode=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnPrintCreditRefID"+Connect.procInitStart+Connect.procInitEnd, "cCode");
        String departmentCode=systems.getValue(OpenMSApp.Database_A, "Select * from Department where vDepartmentName='"+departmentName+"'", "cDepartmentCode");

        String solidReceivablesAccountCode=systems.getValue(OpenMSApp.Database_A, "Select * from Account where vAccountName='"+solidReceivablesAccountName+"'", "cAccountCode");
        String solidReceivablesActivity=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+solidReceivablesAccountCode+"'", "cActivity");
        String transTypeCode=systems.getValue(OpenMSApp.Database_A, "Select * from TransactionType where vTransactionType='"+transactionType+"'", "cTransactionTypeCode");
        System.out.println("CreditOrdercode= "+solidReceivablesOrderCode);
        System.out.println("departmentcode= "+departmentCode);
//---

        String solidPayablesAccountName=String.valueOf(jSolidPayablesAccountNameComboBox.getSelectedItem()).trim();
        solidPayablesOrderCode=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnPrintCreditOrderCode"+Connect.procInitStart+Connect.procInitEnd, "cCode");

        String solidPayablesAccountCode=systems.getValue(OpenMSApp.Database_A, "Select * from Account where vAccountName='"+solidPayablesAccountName+"'", "cAccountCode");
        String solidPayablesActivity=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+solidPayablesAccountCode+"'", "cActivity");
        System.out.println("CreditOrdercode= "+solidPayablesOrderCode);
        System.out.println("departmentcode= "+departmentCode);

        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+"  prnInsCreditOrderOnOrder"+Connect.procInitStart+"?,?,?,?,?,?,?,?,?,?,?,?,?"+Connect.procInitEnd);
         try{
                    statement.setString(1,String.valueOf(merchantIDComboBox.getSelectedItem()).trim());
                    statement.setString(2,solidReceivablesAccountCode.trim());
                    statement.setString(3,OpenMSApp.LoginCode.trim());    
                    statement.setString(4,jTransactionNoTextField.getText().trim());    
                    statement.setString(5,new String(String.valueOf(transYearComboBox.getSelectedItem()).trim()+"-"+systems.getMonthDigit(String.valueOf(transMonthComboBox.getSelectedItem()).trim())+"-"+
                            String.valueOf(transDayComboBox.getSelectedItem()).trim()));
                    statement.setString(6,transTypeCode);
                    statement.setString(7,getCostOrderCode());
                    statement.setString(8,systems.converToRealMoneyFormat(jTotAmountTextField.getText().trim()));
                    statement.setString(9,departmentCode);
                    statement.setString(10,solidReceivablesActivity.trim());
                    statement.setString(11,"IPC");
                    statement.setString(12,refCode);
                    statement.setString(13,systems.converToRealMoneyFormat(jToBalanceTextField.getText().trim()));
            }
            catch(Exception e)
            {
                System.out.println("NewSolidLoanOrder1.makeOrder() gave error ! "+e);
            }
        Connect.executeUpdateStatement(statement);
        
        int x=tableObject.length;
        int y=0,zeros=0;
        while(y<x)
        {
            if(!jTable1.getValueAt(y,3).equals("0"))
            {
                statement=Connect.createStatement(Connect.procInit+"  prnInsCreditOrderSummaryOnOrder"+Connect.procInitStart+"?,?,?,?,?"+Connect.procInitEnd);
             try{
                        statement.setString(1,solidReceivablesOrderCode.trim());
                        statement.setString(2,jTable1.getValueAt(y,1).toString().trim());
                        statement.setString(3,jTable1.getValueAt(y,2).toString().trim()+" [Q="+jTable1.getValueAt(y,3)/*+systems.getValue(OpenMSApp.Database_A, "Select * from Item Where vName='"+jTable1.getValueAt(y,2)+"'", 4)*/+", R="+jTable1.getValueAt(y,4)+"]");
                        statement.setString(4,systems.converToRealMoneyFormat(jTable1.getValueAt(y,5).toString().trim()));
                        statement.setInt(5,Integer.parseInt(jTable1.getValueAt(y,0).toString().trim())-zeros);
                }
                catch(Exception e)
                {
                        System.out.println("NewSolidLoanOrder2.makeOrder() gave error ! "+e);
                }
            Connect.executeUpdateStatement(statement);
            }
            else
            {zeros++;}
        y+=1;
        if(y==x){break;}
        }

        statement=Connect.createStatement(Connect.procInit+"  prnInsCreditOrderOnOrder"+Connect.procInitStart+"?,?,?,?,?,?,?,?,?,?,?,?,?"+Connect.procInitEnd);
         try{
                    statement.setString(1,String.valueOf(merchantIDComboBox.getSelectedItem()).trim());
                    statement.setString(2,solidPayablesAccountCode.trim());
                    statement.setString(3,OpenMSApp.LoginCode.trim());
                    statement.setString(4,jTransactionNoTextField.getText().trim());
                    statement.setString(5,new String(String.valueOf(transYearComboBox.getSelectedItem()).trim()+"-"+systems.getMonthDigit(String.valueOf(transMonthComboBox.getSelectedItem()).trim())+"-"+
                            String.valueOf(transDayComboBox.getSelectedItem()).trim()));
                    statement.setString(6,transTypeCode);
                    statement.setString(7,getCostOrderCode());
                    statement.setString(8,systems.converToRealMoneyFormat(jTotAmountTextField.getText().trim()));
                    statement.setString(9,departmentCode);
                    statement.setString(10,solidPayablesActivity.trim());
                    statement.setString(11,"IPC");
                    statement.setString(12,refCode);
                    statement.setString(13,systems.converToRealMoneyFormat(jToBalanceTextField.getText().trim()));
            }
            catch(Exception e)
            {
                System.out.println("NewSolidLoanOrder3.makeOrder() gave error ! "+e);
            }
        Connect.executeUpdateStatement(statement);

        int xi=tableObject.length;
        int yi=0;zeros=0;
        while(yi<xi)
        {
            if(!jTable1.getValueAt(y,3).equals("0"))
            {
                    statement=Connect.createStatement(Connect.procInit+"  prnInsCreditOrderSummaryOnOrder"+Connect.procInitStart+"?,?,?,?,?"+Connect.procInitEnd);
             try{
                        statement.setString(1,solidPayablesOrderCode.trim());
                        statement.setString(2,jTable1.getValueAt(yi,1).toString().trim());
                        statement.setString(3,jTable1.getValueAt(yi,2).toString().trim()+" [Q="+jTable1.getValueAt(yi,3)/*+systems.getValue(OpenMSApp.Database_A, "Select * from Item Where vName='"+jTable1.getValueAt(y,2)+"'", 4)*/+", R="+jTable1.getValueAt(yi,4)+"]");
                        statement.setString(4,systems.converToRealMoneyFormat(jTable1.getValueAt(yi,5).toString().trim()));
                        statement.setInt(5,Integer.parseInt(jTable1.getValueAt(yi,0).toString().trim())-zeros);
                }
                catch(Exception e)
                {
                        System.out.println("NewSolidLoanOrder4.makeOrder() gave error ! "+e);
                }
            Connect.executeUpdateStatement(statement);
            }
            else
            {zeros++;}
        yi+=1;
        if(yi==xi){break;}
        }

        Connect.alert="Y";
        Connect.closeConnection();
        //reset();
        resetTable();
    }
    public void printReceipt()
    {
        //java.lang.Runtime run=java.lang.Runtime.getRuntime();
        try
        {
            NoteWriter note=new NoteWriter();
            note.writeReceipt(solidReceivablesOrderCode,"",1);
            
            if(OpenMSApp.d==null)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+solidReceivablesOrderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);
            }
            else if(OpenMSApp.d.isVisible()==false)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+solidReceivablesOrderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);            
            }
            else{
                OpenMSApp.d.setTitle("Preview Receipt - "+solidReceivablesOrderCode);
                OpenMSApp.d.doTas(1);
                OpenMSApp.d.transferFocus();                
            }
            
            /*
            run.exec("explorer "+Configuration.officialReceiptPath);
            run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");       
             * 
             */
        }
        catch(Exception e)
        {
            System.out.println("Error while printing receipt ! "+e);
        }
    }
    public void printReceipt2()
    {
        java.lang.Runtime run=java.lang.Runtime.getRuntime();
        try
        {
            NoteWriter note=new NoteWriter();
            note.writeReceipt(solidPayablesOrderCode,"",1);         
            if(OpenMSApp.d==null)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+solidPayablesOrderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);
            }
            else if(OpenMSApp.d.isVisible()==false)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+solidPayablesOrderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);        
            }
            else{
                OpenMSApp.d.setTitle("Preview Receipt - "+solidPayablesOrderCode);
                OpenMSApp.d.doTas(1);
                OpenMSApp.d.transferFocus();                
            }
            /*
            run.exec("explorer "+Configuration.officialReceiptPath);
            run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");       
             * 
             */
        }
        catch(Exception e)
        {
            System.out.println("Error while printing receipt 2 ! "+e);
        }
    }
    public void selectUserDefault()
    {
        if(jCheckBox4.isSelected()==false)
        {
            merchantIDComboBox.setSelectedItem("VD0000001");
            jTransactionTypeComboBox.setSelectedItem("CASH");
            jSolidReceivablesAccountNameComboBox.setSelectedItem("STOCK A/C NGN");
            jSolidPayablesAccountNameComboBox.setSelectedItem("STOCK ON CREDIT A/C NGN");
            jRefDepartmentComboBox.setSelectedItem("MANAGEMENT");
            String curDay=systems.getDateDay(systems.getDateValue(OpenMSApp.Database_A, "Select NOW()", 1));
            String curMonth=systems.getDateMonth(systems.getDateValue(OpenMSApp.Database_A, "Select NOW()", 1));
            String curYear=systems.getDateYear(systems.getDateValue(OpenMSApp.Database_A, "Select NOW()", 1));        
            transMonthComboBox.setSelectedItem(curMonth);
            transDayComboBox.setSelectedItem(curDay);
            transYearComboBox.setSelectedItem(curYear);
        }
    }
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. New Inventory Payable Credit Order - Processing Request");
            thread.sleep(500);
            this.setTitle("::. New Inventory Payable Credit Order - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. New Inventory Payable Credit Order - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. New Inventory Payable Credit Order - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
            setTitle("::. New Inventory Payable Credit Order By User ("+OpenMSApp.EmployeeName+")");
    }
    public void resetDate()
    {
        java.util.Calendar calendar= java.util.Calendar.getInstance();
        //java.util.Date currentDate= new java.util.Date();
        jDateTextField.setText(String.valueOf(calendar.getTime()));
    }
    public void resetMerchantID()
    {
        String[] merchant=systems.getTableDataArray(OpenMSApp.Database_A,"vwMerchant",1);
        merchant[0]="-- Select --";
        merchantIDComboBox.setModel(new DefaultComboBoxModel(merchant));
        jNameTextField.setText("");
    }
    public void resetRefDepartment()
    {
        String[] department=systems.getTableDataArray(OpenMSApp.Database_A,"Department",2);
        department[0]="-- Select --";

        jRefDepartmentComboBox.setModel(new DefaultComboBoxModel(department));
    }
    public void resetCostOrderCode()
    {/*
        String[] costOrderCode=systems.getTableDataArray(OpenMSApp.Database_A,"vwCreditCostOrder",1);
        costOrderCode[0]="-- Select --";

        jCostOrderCodeComboBox.setModel(new DefaultComboBoxModel(costOrderCode));*/
    }
    public void resetSolidReceivablesAccountName()
    {
        String[] actName=systems.getTableDataArray(OpenMSApp.Database_A,"vwInventoryAccount",2);
        actName[0]="-- Select --";

        jSolidReceivablesAccountNameComboBox.setModel(new DefaultComboBoxModel(actName));
        jSRActUnitTextField.setText("");
    }
    public void resetSolidPayablesAccountName()
    {
        String[] actName=systems.getTableDataArray(OpenMSApp.Database_A,"vwSolidPayablesAccount",2);
        actName[0]="-- Select --";

        jSolidPayablesAccountNameComboBox.setModel(new DefaultComboBoxModel(actName));
        jSPActUnitTextField.setText("");
    }
    public void resetTransactionType()
    {
        String[] transType=systems.getTableDataArray(OpenMSApp.Database_A,"TransactionType",2);
        transType[0]="-- Select --";

        jTransactionTypeComboBox.setModel(new DefaultComboBoxModel(transType));
    }
    public void resetItem()
    {
        String[] dbItem=systems.getTableDataArray(OpenMSApp.Database_A, "Item order by vName", 2);
        javax.swing.JComboBox combo=new javax.swing.JComboBox(dbItem);
        javax.swing.table.TableColumn comboColumn=jTable1.getColumnModel().getColumn(1);
        comboColumn.setCellEditor(new javax.swing.DefaultCellEditor(combo));
    }
    public void resetField()
    {
        jTotAmountTextField.setText("0.0");
        jNameTextField.setText("");
        jTransactionNoTextField.setText("");
        jSRActUnitTextField.setText("");
        jAmtDueTextField.setText(".");
        jToBalanceTextField.setText("");
        jSolidPayablesAccountNameComboBox.setSelectedItem("-- Select --");
        jSolidReceivablesAccountNameComboBox.setSelectedItem("-- Select --");
        resetDate();
    }
    private void disableControls()
    {
        jTransactionNoTextField.setEnabled(false);
        jAmtDueTextField.setEnabled(false);
        addRowButton.setEnabled(false);
        deleteRowButton.setEnabled(false);
        makeOrderButton.setEnabled(false);
        merchantIDComboBox.setEnabled(false);
        jTransactionTypeComboBox.setEnabled(false);
        transMonthComboBox.setEnabled(false);
        transDayComboBox.setEnabled(false);
        transYearComboBox.setEnabled(false);
        jSolidReceivablesAccountNameComboBox.setEnabled(false);
        jSolidPayablesAccountNameComboBox.setEnabled(false);
        jRefDepartmentComboBox.setEnabled(false);
        jCheckBox4.setEnabled(false);
        jCheckBox3.setEnabled(false);              
    }
    private void enableControls()
    {
        jTransactionNoTextField.setEnabled(true);
        jAmtDueTextField.setEnabled(true);
        addRowButton.setEnabled(true);
        deleteRowButton.setEnabled(true);
        makeOrderButton.setEnabled(true);
        merchantIDComboBox.setEnabled(true);
        jTransactionTypeComboBox.setEnabled(true);
        transMonthComboBox.setEnabled(true);
        transDayComboBox.setEnabled(true);
        transYearComboBox.setEnabled(true);
        jSolidPayablesAccountNameComboBox.setEnabled(true);
        jSolidReceivablesAccountNameComboBox.setEnabled(true);
        jRefDepartmentComboBox.setEnabled(true);
        jCheckBox4.setEnabled(true);
        jCheckBox3.setEnabled(true);     
        setTitle("::. New Inventory Payable Credit Order By User ("+OpenMSApp.EmployeeName+")");
    }
    public void resetCombo()
    {
        resetItem();
        resetMerchantID();
        resetRefDepartment();
        resetTransactionType();
        resetSolidReceivablesAccountName();
        resetSolidPayablesAccountName();
        resetCostOrderCode();
        resetTransMonth();
        resetTransDay("");
        resetTransYear();
        resetItem();
        jSolidPayablesAccountNameComboBox.setSelectedItem("-- Select --");
        jSolidReceivablesAccountNameComboBox.setSelectedItem("-- Select --");
    }
    public void reset()
    {
        resetField();
        resetTable();
        resetCombo();
        selectUserDefault();
    }
    public void resetTable()
    {
        tableObject=new Object[][]{{1,null,null,null,null,null}};
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Item","Description", "Quantity", "Rate", "Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true, true, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
            resetItem();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addRowButton;
    private javax.swing.JButton deleteRowButton;
    private javax.swing.JTextField jAmtDueTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JComboBox jCostOrderCodeComboBox;
    private javax.swing.JTextField jDateTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jNameTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jRefDepartmentComboBox;
    private javax.swing.JTextField jSPActUnitTextField;
    private javax.swing.JTextField jSRActUnitTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jSolidPayablesAccountNameComboBox;
    private javax.swing.JComboBox jSolidReceivablesAccountNameComboBox;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jToBalanceTextField;
    private javax.swing.JTextField jTotAmountTextField;
    private javax.swing.JTextField jTransactionNoTextField;
    private javax.swing.JComboBox jTransactionTypeComboBox;
    private javax.swing.JButton makeOrderButton;
    private javax.swing.JComboBox merchantIDComboBox;
    private javax.swing.JComboBox transDayComboBox;
    private javax.swing.JComboBox transMonthComboBox;
    private javax.swing.JComboBox transYearComboBox;
    // End of variables declaration//GEN-END:variables

}
